package com.cursino.wilson.game.card;

import java.util.LinkedList;
import java.util.Random;

/**
 * Shoedeck class, will represent a simple shoe deck of cards.
 * @author <a href="mailto:"wilson.cursino@gmail.com"> Wilson Soethe Cursino </a>
 * @since 1.0
 */
public class Shoedeck {

    private LinkedList<Card> shoe;// "stack" capability for the list

    public LinkedList<Card> getShoe() {
        return shoe;
    }

    public Shoedeck(int decks) {
        shoe = new LinkedList<Card>();
        // for each shoe
        for (int i = 0; i < decks; i++) {
            // create cards with value
            for (CardValue value : CardValue.values()) {
                // and suit
                for (CardSuit type : CardSuit.values()) {
                    shoe.add(new Card(value, type));
                }
            }
        }
    }
    public Card popCard() {
        return shoe.pop();
    }
    public void shuffle() {
        // We could use a better implementation, like the Collections.shuffle(..);
        // Let's just create a simple shuffle
        Random random = new Random();
        for (int i = 0; i < shoe.size(); i++) {
            int index = random.nextInt(i + 1);
            // Simple swap
            Card card = shoe.get(index);
            shoe.set(index, shoe.get(i));
            shoe.set(i, card);
        }
    }
    /**
     * Gets the qty cards in shoe by card value.
     * @return the qty in shoe by value
     */
    public int[] getQtyInShoeByValue() {
        int[] result = new int[10];
        for (Card card : shoe) {
            result[card.getValue().getValue()] = ++result[card.getValue().getValue()];
        }
        return result;
    }
}
